package src.mian.java;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FsUrlStreamHandlerFactory;

public class HDFSFileReader {

    public static void main(String[] args) throws IOException {
        Configuration conf = new Configuration();
        URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory(conf));

        String hdfsFileURL = "hdfs://192.168.254.100:8020/test/poem.txt";
        URL url = new URL(hdfsFileURL);
        InputStream inputStream = url.openStream();

        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream,"gbk"));
        String line;
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }

        reader.close();
        inputStream.close();
    }
}
